<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('著作列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>序号：</label>
                            <input type="text" name="serialNumber"/>
                        </li>
                        <li>
                            <label>类别：</label>
                            <select id="category" name="category" class="form-control" type="text" ></select>
                        </li>
                        <li>
                            <label>著作名称：</label>
                            <input type="text" name="titleOfWork"/>
                        </li>
                        <li>
                            <label>ISBN/CIP：</label>
                            <input type="text" name="isbnCip"/>
                        </li>
                        <li>
                            <label>出版社：</label>
                            <input type="text" name="press"/>
                        </li>
                        <li>
                            <label>主编：</label>
                            <input type="text" name="chiefEditor"/>
                        </li>
                        <li>
                            <label>副主编：</label>
                            <input type="text" name="deputyEditorInChief"/>
                        </li>
                        <li>
                            <label>编者：</label>
                            <input type="text" name="editor"/>
                        </li>
                        <li class="select-time">
                            <label>出版时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginPublicationTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endPublicationTime]"/>
                        </li>
                        <li>
                            <label>赋分：</label>
                            <input type="text" name="naturalEndowments"/>
                        </li>
                        <li>
                            <label>奖励：</label>
                            <input type="text" name="reward"/>
                        </li>
                        <li>
                            <label>上传人：</label>
                            <input type="text" name="applicant"/>
                        </li>
                        <li>
                            <label>审批：</label>
                            <select name="examineApprove" th:with="type=${@dict.getType('admin_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>备案：</label>
                            <select name="keepOnRecord" th:with="type=${@dict.getType('admin_records')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>


        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('ruoyi:work:edit')}]];
    var removeFlag = [[${@permission.hasPermi('ruoyi:work:remove')}]];
    var onRecordsDatas = [[${@dict.getType('sys_records')}]];
    var statusDatas = [[${@dict.getType('sys_status')}]];
    var prefix = ctx + "ruoyi/work";
    classes();
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "著作",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'serialNumber',
                    title: '序号'
                },
                {
                    field: 'category',
                    title: '类别'
                },
                {
                    field: 'titleOfWork',
                    title: '著作名称'
                },
                {
                    field: 'isbnCip',
                    title: 'ISBN/CIP'
                },
                {
                    field: 'press',
                    title: '出版社'
                },
                {
                    field: 'chiefEditor',
                    title: '主编'
                },
                {
                    field: 'deputyEditorInChief',
                    title: '副主编'
                },
                {
                    field: 'editor',
                    title: '编者'
                },
                {
                    field: 'publicationTime',
                    title: '出版时间'
                },
                {
                    field: 'naturalEndowments',
                    title: '赋分'
                },
                {
                    field: 'reward',
                    title: '奖励'
                },
                {
                    field: 'applicant',
                    title: '上传人',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return '<a href="javascript:void(0)" onclick="chakan(\'' + row.uid + '\')">' + value + '</a>';
                    }
                },
                // {
                //     field: 'file',
                //     title: '文件'
                // },
                {
                    title: '查看文件',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.file==null||row.file==''){
                            actions.push('<p>未提交</p> ');
                            return actions.join('');
                        }else{
                            actions.push('<a href=\''+row.file+'\' target="_blank" rel="nofollow">查看文件</a> ');
                            return actions.join('');
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'examineApprove',
                    title: '审批',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'keepOnRecord',
                    title: '备案',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(onRecordsDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.examineApprove === 1) {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="tongguo(\'' + row.id + '\')"><i class="fa fa-user"></i>通过审批</a> ');
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="bohui(\'' + row.id + '\')"><i class="fa fa-user"></i>驳回审批</a> ');
                        } else if (row.keepOnRecord == 2) {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="beian(\'' + row.id + '\')"><i class="fa fa-user"></i>通过备案</a> ');
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="beianbohui(\'' + row.id + '\')"><i class="fa fa-user"></i>驳回备案</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function tongguo(id) {
        $.modal.confirm("确认要通过申请吗?", function () {
            var url = prefix + "/tongguo";
            var data = {"id": id};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function bohui(id) {
        $.modal.confirm("确认要驳回申请吗?", function () {
            var url = prefix + "/bohui";
            var data = {"id": id};
            $.operate.submit(url, "post", "json", data);
        });
    }
    function beianbohui(id) {
        $.modal.confirm("确认要驳回备案吗?", function () {
            var url = prefix + "/beianbohui";
            var data = {"id": id};
            $.operate.submit(url, "post", "json", data);
        });
    }
    function beian(id) {
        $.modal.confirm("确认要申报备案吗?", function () {
            var url = prefix + "/beian";
            var data = {"id": id};
            $.operate.submit(url, "post", "json", data);
        });
    }

    function chakan(uid) {
        var url = prefix + '/chakan/' + uid;
        $.modal.openTab("查看详情", url);
    }
    
    function classes() {
        let uname="全部";
        $.ajax({
            url:prefix+"/category",
            type:"get",
            dataType:"json",
            data:{},
            success:function (data) {
                if (data.length>0){
                    $("#category").append("<option>"+uname+"</option>")
                    for (i in data){
                        $("#category").append("<option>"+data[i].category+"</option>")
                    }
                }else {
                    $("#category").append("<option>暂无数据</option>")
                }
            }

        })
    }
</script>
</body>
</html>